import {Component, ElementRef, OnDestroy, OnInit, TemplateRef} from "@angular/core";
import {NzMessageService} from "ng-zorro-antd";
import {FetchService} from "../../../../core/net/fetch.service";
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
import {Topology, Rect} from 'topology-core';
import {Options} from 'topology-core/options';
import {DomSanitizer, SafeResourceUrl} from "@angular/platform-browser";
import {Router} from "@angular/router";
import {NzModalRef, NzModalService} from "ng-zorro-antd/modal";

@Component({
  selector: 'app-emergency-home',
  templateUrl: './emergency-home.component.html',
  styleUrls: ['../emergency-dispatch-common.scss', './emergency-home.component.scss']
})

export class EmergencyHomeComponent implements OnInit, OnDestroy {
  infoShow = false;
  pptnrList = [];

  // 文件预览
  tplModal: NzModalRef;
  fileSrc = '';
  fileType = '';
  fileId = '';
  fileTypeList = ['pdf', 'png', 'jpg'];

  constructor(
    private fb: FormBuilder,
    private message: NzMessageService,
    private fetchService: FetchService,
    private router: Router,
    private modal: NzModalService,
    private sanitizer: DomSanitizer
  ) {
  }

  ngOnInit(): void {
    this.getPptnrData();
  }

  ngOnDestroy(): void {
  }

  getPptnrData(): void {
    this.fetchService.post<any>('intake/wrsPptnR/ddList', {description: 1}).subscribe(res => {
      this.pptnrList = res.data;
    });
  }

  goPage(name): void {
    this.router.navigate([`/realtime-control/emergency-${name}`]);
  }

  viewFile(tplContent: TemplateRef<{}>): void {
    const that = this;
    this.fileSrc = `${(window as any).environment.apiBaseUrl}comm/file/view/b2b7be7f4831415ea413845a12d6de97`;

    this.tplModal = this.modal.create({
      nzTitle: '文件预览',
      nzContent: tplContent,
      nzWidth: 1100,
      nzStyle: {top: '20px'},
      nzClassName: 'custom-modal',
      nzFooter: null,
      nzMaskClosable: false,
      nzClosable: true,
      nzOnCancel(): void {
        that.destroyModal();
      }
    });
  }

  destroyModal() {
    this.tplModal.destroy();
  }
}
